<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="icon" href="/res/images/ico.png" type="image/x-icon">
    <script src="/res/guacamole/guacamole.min.js"></script>
    <style>
        body {
            margin: 0;
            position: fixed;
            top: 0px;
            bottom: 0px;
            left: 0px;
            right: 0px;
            overflow: hidden;
        }
        /*#display {
            width: 100%;
            right: 100%;
            text-align: center;
            display: inline-block;
            overflow: hidden;
        }*/
    </style>
</head>
<body>
<div id="display"></div>
</body>
<script>
    // Get display div from document
    var display = document.getElementById("display");
    // Instantiate client, using an HTTP tunnel for communications.
    var guac = new Guacamole.Client(
        new Guacamole.WebSocketTunnel("/sys/webSocketTunnel") // websocket连接时开启
    );


    // Add client to display div
    display.appendChild(guac.getDisplay().getElement());
    // Error handler
    guac.onerror = function (error) {
        alert(error.message);
    };
    // Connect
    guac.connect("protocol=ssh&hostname=192.168.3.8&port=22&width=" + document.body.clientWidth + "&height=" + document.body.offsetHeight);
    // guac.connect("protocol=vnc&hostname=192.168.3.8&port=5900&width=" + document.body.clientWidth + "&height=" + document.body.offsetHeight);
    // guac.connect("protocol=rdp&hostname=192.168.3.120&port=3389&width=" + document.body.clientWidth + "&height=" + document.body.offsetHeight);

    // Disconnect on close
    window.onunload = function () {
        guac.disconnect();
    }

    /*display.oncontextmenu = function (e) {
        // 执行代码块
        e.preventDefault();
        var outputStream = guac.createClipboardStream("text/plain");
        //将输出流包装在writer中
        var writer = new Guacamole.StringWriter(outputStream);
        // 发短讯
        writer.sendText("root");
        //关闭作家和流
        writer.sendEnd();
    }*/

    // Mouse
    var mouse = new Guacamole.Mouse(guac.getDisplay().getElement());
    mouse.onmousedown =
        mouse.onmouseup =
            mouse.onmousemove = function (mouseState) {
                guac.sendMouseState(mouseState);
            };
    // Keyboard
    var keyboard = new Guacamole.Keyboard(document);
    keyboard.onkeydown = function (keysym) {
        guac.sendKeyEvent(1, keysym);
    };
    keyboard.onkeyup = function (keysym) {
        guac.sendKeyEvent(0, keysym);
    };

</script>
</html>